using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CarMaritalStatusDB
    {
        public CarMaritalStatusDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarMaritalStatus maritalstatus)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarMaritalStatusInsertUpdateSingleItem]";
            
            SortedList _sPara = new SortedList();
            
            #region Parameter
            _sPara.Add("@ProviderCarMaritalStatusId", maritalstatus.ProviderCarMaritalStatusId);
            _sPara.Add("@ProviderCompanyId", maritalstatus.ProviderCompanyId);
            _sPara.Add("@CXMaritalStatusId", maritalstatus.CXMaritalStatusId);
            _sPara.Add("@MaritalStatusDescription", maritalstatus.MaritalStatusDescription);
            _sPara.Add("@Sex", maritalstatus.Sex);
            _sPara.Add("@MaritalStatusValue", maritalstatus.MaritalStatusValue);
            _sPara.Add("@RefCEUserId", maritalstatus.RefCEUserId);
            _sPara.Add("@Status", maritalstatus.Status);
            _sPara.Add("@Finfo1", maritalstatus.FInfo1);
            _sPara.Add("@Dinfo1", maritalstatus.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        
        public bool Delete(Int64 ProviderCarMaritalStatusId, Int64 ProviderCompanyId)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarMaritalStatusDeleteSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@ProviderCarMaritalStatusId", ProviderCarMaritalStatusId);
            _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result > 0;
        }

        public CarMaritalStatusList GetProviderCarMaritalStatusList(Int64 ProviderCompanyId)
        {
            CarMaritalStatusList _maritalstatuslist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarMaritalStatusSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _maritalstatuslist = new CarMaritalStatusList();
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        CarMaritalStatus _maritalstatus = new CarMaritalStatus();
                        _maritalstatus = FillDataRecord(_dt, i);
                        _maritalstatuslist.Add(_maritalstatus);
                    }
                }
            }
            return _maritalstatuslist;
        }


        public CarMaritalStatus GetProviderCarMaritalStatus(Int64 ProviderCompanyId, Int32 CXCarMaritalStatusId)
        {
            CarMaritalStatus _maritalstatus = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarMaritalStatusSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@CXCarMaritalStatusId", CXCarMaritalStatusId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _maritalstatus = new CarMaritalStatus();
                    _maritalstatus = FillDataRecord(_dt, 0);
                }
            }
            return _maritalstatus;
        }

        public CarMaritalStatus GetProviderCarMaritalStatus(Int64 ProviderCarMaritalStatusId)
        {
            CarMaritalStatus _maritalstatus = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarMaritalStatusSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCarMaritalStatusId", ProviderCarMaritalStatusId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _maritalstatus = new CarMaritalStatus();
                    _maritalstatus = FillDataRecord(_dt, 0);
                }
            }
            return _maritalstatus;
        }

        public DataTable GetCXMaritalStatus()
        {
            MyDatabase _db = new MyDatabase();
            DataTable _dtResult = new DataTable("Result");
            string _spName = "sprocMaritalStatusSelectItemList";
            SortedList _sPara = new SortedList();

            _dtResult = _db.GetDataTableBySP(_spName, _sPara);
            return _dtResult;
        }

        private CarMaritalStatus FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarMaritalStatus myCarMaritalStatus = new CarMaritalStatus();
            myCarMaritalStatus.ProviderCarMaritalStatusId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCarMaritalStatusId"].ToString());
            myCarMaritalStatus.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCarMaritalStatus.MaritalStatusDescription = myDataTable.Rows[RowId]["MaritalStatusDescription"].ToString();
            myCarMaritalStatus.CXMaritalStatusId = Convert.ToInt32(myDataTable.Rows[RowId]["CXMaritalStatusId"].ToString());
            myCarMaritalStatus.Sex = myDataTable.Rows[RowId]["Sex"].ToString();
            myCarMaritalStatus.MaritalStatusValue = Convert.ToSingle(myDataTable.Rows[RowId]["MaritalStatusValue"].ToString());
            myCarMaritalStatus.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCarMaritalStatus.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());

            if (myDataTable.Rows[RowId]["FInfo1"].ToString() != "")
                myCarMaritalStatus.FInfo1 = Convert.ToSingle(myDataTable.Rows[RowId]["FInfo1"].ToString());

            if (myDataTable.Rows[RowId]["DInfo1"].ToString() != "")
                myCarMaritalStatus.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["DInfo1"].ToString());
            else
                myCarMaritalStatus.DInfo1 = Convert.ToDateTime(myDataTable.Rows[RowId]["ModifiedDate"].ToString());

            return myCarMaritalStatus;
        }
        
    }
}